﻿using System;
using System.Data;
using System.Linq;
using System.Windows;
using WPFExcelReport.Chart;
using System.Windows.Controls;
using WPFExcelReport.Helpers;
using System.ComponentModel;
using ReflectionStudio.Core.Events;
using System.Collections.Generic;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class UIVKPOS : ViewBase
    {
        public UIVKPOS()
        {
        }

        public override void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
            FTAUTOSUM = true;
            TCOUNT1 = "行数";
            TKEY1 = "数量";
            SKEY1 = "VKPSA";
            KEY1 = "VKPMENGE1";
            TKEY2 = "本币";
            SKEY2 = "VKPSA";
            KEY2 = "VKPPOSWERT";
            TKEY3 = "交易";
            SKEY3 = "VKPSA";
            KEY3 = "BUVALUE";
            TBMain.Merge(TMV.VAF.TBMain);
            TBMain.Merge(TMV.VA.TBMain);
            if (!TBMain.Columns.Contains("BUVALUE"))
            {
                TBMain.Columns.Add("BUVALUE", typeof(decimal));
            }
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVKP = dwMaster;
            IsInactive = false;
            VKPAUFMART = TMV.VKPAUFMART.PadRight(2);
            VKPVERPART = TMV.VKPVERPART.PadRight(2);
            if (dwMaster == null)
            {

                KEY = "";
                VART = "";
                TXTISIND = "";
                KEY = "";
                BSTSTA = " ";
                MEEH = "".PadRight(3);
                AUF = "";
                POSTYP = "";
                KUNDNR = "";
                LIEFTERM = "20160621";
            }
            else
            {
                if (TMV.VKPSA == "IN")
                    IsInactive = true;

                KUNDNR = TMV.VKPKUNDNR;
                BSTSTA = TMV.VKPBSTSTA;
                MEEH = TMV.VKPMEEH;
                POSTYP = TMV.VKPPOSTYP;
                if (IsInactive)
                    return;
                KEY = TMV.VKPAUFKRS + TMV.VKPAUFLFD + TMV.VKPAUFPOS + TMV.VKPKUNDNR + "K";
                VKP = TMV.VKPAUFKRS + TMV.VKPAUFLFD + TMV.VKPAUFPOS;
                AUF = "K" + VKP + LIEFSCH.PadRight(8);
                VART = TMV.VKPKOLL + TMV.VKPART + TMV.VKPFARBE + TMV.VKPKUNDNR;
                ENVMAIN["VKP"] = "K" + TMV.VKPAUFKRS + TMV.VKPAUFLFD + TMV.VKPAUFPOS + TMV.VKPKUNDNR + LIEFSCH.PadRight(8);
                if (MEEH.Trim() == "M" || MEEH.Trim() == "Y")
                {
                    IsMTR = true;
                    IsKG = false;
                }
                else
                {
                    IsKG = true;
                    IsMTR = false;
                }
                if (app.company != "UBT")
                {
                    TXTISIND = (TMV.VKPAUFKRS + TMV.VKPAUFLFD + TMV.VKPAUFPOS).PadRight(60);
                }
                PCS = TMV.VKPZUSATZ.PadRight(35).Substring(30, 5).Trim();
                OVERSHORT = TMV.VKPZUSATZ.Substring(0, 30).Trim(); 
                try
                {
                    BPRICE = double.Parse(TMV.VKPPREIS) * 0.001 * double.Parse(TMV.VKPPREHFKT) * 0.001 * 0.001 * double.Parse(TMV.VKPMEEHFKT) * 0.001 * 0.001 * TMV.VKPKURS * 0.0001;

                }
                catch(Exception ex)
                {

                }
            }
            PRODREQ();
            CHKTSTPOSTYP(TMV.VKPAUFART);
            ChkWFChg(IsChkWF);
            LIEFTERM = TMV.VKPLIEFTERM.ToString();
        }
        public override void ChkWFChg(bool value)
        {
            base.ChkWFChg(value);
        }
        public void OnVKKChg(DataRow _dwVKK)
        {
            if (_dwVKK == null)
            {
                KRS = "";
                LFD = "";
                LIEFSCH = "";
            }
            else
            {
                KRS = _dwVKK["VKKAUFKRS"].ToString();
                LFD = _dwVKK["VKKAUFLFD"].ToString();
                if (_dwVKK.Table.Columns.Contains("VVTLIEFSCH"))
                {
                    LIEFSCH = dwVKK["VVTLIEFSCH"].ToString();
                }
            }
            VKKLOAD(_dwVKK);
        }

        public virtual void PRODREQ()
        {
            IsNOTFull = true;
            if (TMV.VKPZUGET >= TMV.VKPMENGE1)
            {
                IsNOTFull = false;
            }
        }
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            base.QueryCommand(sender, e);
        }
        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            try
            {
                base.OnWorkflowIDChange(e);
                MessageInfo msg = e.Info;
                if (msg.ID == LastMSGID)
                    return;
                LastMSGID = msg.ID;

                string task = msg.MSGTYPE;
                switch (task)
                {
                    case "WDCHG":
                        WDCHG(msg);
                        break;
                    case "VVTCHG":
                        VVTCHG(msg);
                        break;
                    case "VVRELOAD":
                        LIEFSCH = msg.LIEFSCH;
                        filter = "VKPAUFKRS='" + msg.KRS + "' AND VKPAUFLFD='" + msg.LFD + "' AND VKPAUFPOS='" + msg.POS + "'";
                        rows = TBMain.Select(filter);
                        foreach (DataRow row in rows)
                        {
                            //TMV.VVLOAD(row);
                        }
                        break;
                    case "VKPCHK":
                        VKPCHK(msg);
                        break;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public virtual void VKKLOAD(DataRow _dwVKK)
        {
            TBMain.Clear();
            if (_dwVKK == null)
                return;
            SetDefaulPositionType(_dwVKK);
            switch (app.company)
            {
                default:
                case "TST":
                case "SXN":
                    CHKTSTPOSTYP(dwVKK["VKKAUFART"].ToString());
                    break;
            }

        }

        public virtual void SetDefaulPositionType(DataRow _dwVKK)
        {
        }
       
        public virtual void CHKTSTPOSTYP(string aufart)
        {

            switch (aufart)
            {
                default:
                case "NA":
                    POSTYP = "BUL";
                    IsCheckVA = true;
                    IsAutoVRP = false;
                    IsStagePrice = false;
                    IsBasedOnOF = false;
                    break;
                case "TW":
                    POSTYP = "BUL";
                    IsCheckVA = true;
                    IsAutoVRP = false;
                    IsStagePrice = false;
                    IsBasedOnOF = false;
                    break;
                case "T":
                    POSTYP = "BUL";
                    IsCheckVA = true;
                    IsAutoVRP = false;
                    IsStagePrice = false;
                    IsBasedOnOF = false;
                    break;
                case "CO":
                    POSTYP = "CO ";
                    IsCheckVA = true;
                    IsAutoVRP = false;
                    IsStagePrice = true;
                    IsBasedOnOF = false;
                    break;
                case "BO":
                    POSTYP = "BUL";
                    IsCheckVA = true;
                    IsAutoVRP = false;
                    IsStagePrice = false;
                    IsBasedOnOF = true;
                    break;
                case "OF":
                    POSTYP = "OF ";
                    IsCheckVA = false;
                    IsAutoVRP = false;
                    IsStagePrice = true;
                    IsBasedOnOF = false;
                    break;
                case "SM":
                    POSTYP = "SMP";
                    IsCheckVA = false;
                    IsAutoVRP = false;
                    IsStagePrice = false;
                    IsBasedOnOF = false;
                    break;
                case "KS":
                    POSTYP = "KS ";
                    IsCheckVA = true;
                    IsAutoVRP = false;
                    IsStagePrice = false;
                    IsBasedOnOF = false;
                    break;
                case "DS":
                    POSTYP = "DS ";
                    IsCheckVA = true;
                    IsAutoVRP = false;
                    IsStagePrice = false;
                    IsBasedOnOF = false;
                    break;
            }
        }

        public virtual void VKPCHK(MessageInfo msg)
        {
            /*
            if (vwMaster.View == null)
                return;
            vwMaster.View.MoveCurrentTo(-1);*/
            var query = from DataRow row in TBMain.AsEnumerable()
                        where row["VKPAUFKRS"].ToString().Trim() == msg.KRS.Trim()
                        && row["VKPAUFLFD"].ToString().Trim() == msg.LFD.Trim()
                        && row["VKPAUFPOS"].ToString().Trim() == msg.POS.Trim()
                        select row;
            foreach (DataRow row in query)
            {
                int idx = TBMain.Rows.IndexOf(row);
                row["VKPEXART"] = msg.ART;
                //vwMaster.View.MoveCurrentToPosition(idx);
                break;
            }
        }

        public virtual void UPDATEVKP(DataRow _dwVKP)
        {
            TMV.UPDATEVKP(_dwVKP);//计算价值
            TMV.UpdateVKPOS(_dwVKP, app.company, 0);
            UpdateVK04(_dwVKP["VKPAUFKRS"].ToString() + _dwVKP["VKPAUFLFD"].ToString());
            PRODREQ(); 
        }

        public void WDCHG(MessageInfo msg)
        {
            filter = "VKPAUFKRS='" + msg.KRS + "' AND VKPAUFLFD='" + msg.LFD + "' AND VKPAUFPOS='" + msg.POS + "'";
            rows = TBMain.Select(filter);
            foreach (DataRow _dwVKP in rows)
            {
                _dwVKP["VKPSA"] = " ";
                _dwVKP["VKPFIXMASS"] = "F";
                _dwVKP["VKPAENDBEN"] = app.User;
                _dwVKP["VKPAENDDAT"] = MV.date;
                _dwVKP["VKPZUGET"] = Convert.ToDouble(msg.P2);
                _dwVKP["VKPZUGETT1"] = Convert.ToDouble(msg.P2);
                _dwVKP["VKPZUGETT2"] = Convert.ToDouble(msg.P2);
                _dwVKP["VKPZUGETT3"] = Convert.ToDouble(msg.P3);
                _dwVKP["VKPZUGETT4"] = Convert.ToDouble(msg.P4);
            }
        }

        public void VVTCHG(MessageInfo msg)
        {
            filter = "VKPAUFKRS='" + msg.KRS + "' AND VKPAUFLFD='" + msg.LFD + "' AND VKPAUFPOS='" + msg.POS + "'";
            rows = TBMain.Select(filter);
            foreach (DataRow _dwVKP in rows)
            {
                TMV.Ship(_dwVKP, msg);
            }
        }

        public void VKPEND(MessageInfo msg)
        {
            if (dwMaster == null)
                return;
            dwMaster["VKPERL"] = "J";
            dwMaster["VKPERLDAT"] = MV.date;
            dwMaster["VKPERLBEN"] = app.User;
            Update();
        }
        //新建的通用函数
        public override void New()
        {
            if (dwVKK == null)
                return;
            string _date = "", _time = "";
            Helper.GetTime(ref _date, ref _time);
            dwData = TBMain.NewRow();
            TMV.SetUpNewRow(ref dwData);
            dwData["VKPMANDANT"] = app.Mandant;
            dwData["VKPSA"] = VKPSA;
            dwData["VKPAUFKRS"] = KRS;
            dwData["VKPAUFLFD"] = LFD;
            dwData["VKPVB"] = dwVKK["VKKVB"];
            dwData["VKPVG"] = dwVKK["VKKVG"];
            dwData["VKPKOLL"] = KOLL.PadRight(5);
            dwData["VKPART"] = ART.PadRight(24);
            dwData["VKPFARBE"] = FARBE.PadRight(10);
            GetPos(dwData);
            dwData["VKPKUNDNR"] = dwVKK["VKKKUNDNR"];
            dwData["VKPAUFART"] = dwVKK["VKKAUFART"];
            dwData["VKPSACHBE"] = dwVKK["VKKSACHBE"];
            CHKTSTPOSTYP(dwVKK["VKKAUFART"].ToString());
            dwData["VKPPOSTYP"] = POSTYP;
            dwData["VKPKURS"] = Convert.ToDouble(dwVKK["VKKKURS"].ToString());
            dwData["VKPEZEIT"] = _time.Substring(0, 4);
            dwData["VKPMEEHGRP"] = "2";
            dwData["VKPPREHGRP"] = "2";
            dwData["VKPZKDAT"] = dwData["VKPNEUDAT"];
            dwData["VKPLIEFTERM"] = dwData["VKPNEUDAT"];
            //这里会执行一个函数，在TST用于从WS中提取单价，将来可以用于从价格表中提取
            CheckPrice(dwData);
            CheckDelDate(dwData);
            Insert(dwData);

        }

        public void GetPos(DataRow dwBase)
        {
            string value = "0";
            string pos = "000";
            SResult = TMV.QueryVKPOS(dwBase, 20);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                value = row["VKPAUFPOS"].ToString();
                if (value.Trim() == "")
                    value = "0";
                pos = Helper.Right("000" + (Convert.ToInt16(value) + 1).ToString(), 3);
            }
            dwBase["VKPAUFPOS"] = pos;
        }
        /// <summary>
        /// 这是一个虚函数，可以重载
        /// </summary>
        /// <param name="dwData"></param>
        public virtual void CheckPrice(DataRow dwData)
        {

        }

        public virtual void CheckDelDate(DataRow dwData)
        {
            if (app.company != "UBT")
            {
                dwData["VKPLIEFTERM"] = Helper.GetDateAddDays(MV.date, 30);
            }
        }


        public virtual void OnLIEFTERMChg(string _date)
        {
            if (_date.Contains("/")) return;
            TMV.VKPLIEFTERM = double.Parse(_date);

        }
        public virtual void Insert(DataRow _dwVKP)
        {

            TMV.InsertVKPOS(_dwVKP, app.company);
            TBMain.Rows.InsertAt(_dwVKP, 0);
            if (ARTST == "G")
            {
                TMV.NEWGD(_dwVKP, dwVF);
            }
            vwMaster.View.MoveCurrentToFirst();
            if (TxtQty != null)
            {
                TxtQty.SelectAll();
            }
        }

        public override void OnAppModeChg()
        {
            base.OnAppModeChg();
            switch (app.company)
            {
                case "TST":
                    KRS = MV.year.Substring(2, 2);
                    switch (AppMode)
                    {
                        case "TISSUE":
                            // KRS = "S" + MV.year.Substring(3, 1);

                            break;
                        case "TMODE":
                            //KRS = "M" + MV.year.Substring(3, 1);
                            break;
                    }
                    break;
                case "JLT":
                    KRS = "J" + MV.year.Substring(3, 1);
                    break;
            }
        }

        public bool Validate()
        {
            bool IsOK = true;
            try
            {
                if (TxtPrice != null)
                {
                    TxtPrice.Focus();
                }
                TxtQty.Focus();
                if (dwMaster["VKPLIEFTERM"].ToString().Trim().Length < 8)
                {
                    MessageBox.Show("请先输入交期");
                    return false;
                }

                if (dwMaster["VKPART"].ToString().Trim().Length == 0
                || dwMaster["VKPFARBE"].ToString().Length < 10)
                {
                    MessageBox.Show("请先输入品种或色号");
                    return false;
                }
                if (dwMaster["VKPFARBE"].ToString().Length < 10)
                {
                    //MessageBox.Show("请先输入色号");
                    //return false;
                }
                if (IsPrice)
                {
                    if (Convert.ToDouble(dwMaster["VKPPREIS"].ToString()) * 0.001 == 0)
                    {
                        MessageBox.Show("请先输入价格");
                        return false;
                    }
                    if (MEEH.Trim().Length == 0)
                    {
                        if (app.company == "UBT")
                        {
                            MEEH = "M";

                        }
                        else { MessageBox.Show("请先输入单位"); }

                        return false;
                    }
                }
                if (cNOVA != null)
                {
                    if (cNOVA.IsNew)
                    {
                        cNOVA.NewCommand(null, null);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return IsOK;
        }

        public override void Copy()
        {
            base.Copy();
            if (dwMaster == null)
                return;
            DataRow dwData;
            dwData = TBMain.NewRow();
            dwData.ItemArray = dwMaster.ItemArray;
            GetPos(dwData);
            dwData["VKPMENGE1"] = 0;
            dwData["VKPPOSWERT"] = 0;
            //dwData["VKPKDARTNR"] = "".PadRight(24);
            //dwData["VKPKDFARBNR"] = "".PadRight(10);
            //dwData["VKPKDBEZ"] = "".PadRight(30);
            MEEH = "";
            MEEH = dwData["VKPMEEH"].ToString();
            dwVKP["VKPAENDBEN"] = "********";//经过复制新建里的
            Insert(dwData);
        }
        /// <summary>
        /// 新建命令只有一个，也是公用的
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void NewCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            New();
            base.NewCommand(sender, e);
            vwMaster.View.MoveCurrentToFirst();
        }

        public override void EditCommand(object sender, RoutedEventArgs e)
        {
            base.EditCommand(sender, e);
        }

        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
            Update();
            base.SaveCommand(sender, e);
        }

        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null) return;
            TMV.DeleteVKPOS(dwMaster, 1);
            filter = "VKPAUFKRS='" + dwMaster["VKPAUFKRS"].ToString() + "' AND VKPAUFLFD='" + dwMaster["VKPAUFLFD"].ToString() + "' AND VKPAUFPOS='" + dwMaster["VKPAUFPOS"].ToString() + "'";
            UpdateVK04(dwMaster["VKPAUFKRS"].ToString() + dwMaster["VKPAUFLFD"].ToString());
            vwMaster.View.MoveCurrentTo(-1);
            rows = TBMain.Select(filter);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }

        public override void InactiveCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            dwMaster["VKPSA"] = "IN";
            dwData = TBMain.NewRow();
            dwData["VKPMANDANT"] = app.Mandant;
            dwData["VKPSA"] = "IN";
            dwData["VKPAUFKRS"] = dwMaster["VKPAUFKRS"];
            dwData["VKPAUFLFD"] = dwMaster["VKPAUFLFD"];
            dwData["VKPAUFPOS"] = " AND VKPAUFPOS='" + dwMaster["VKPAUFPOS"].ToString() + "'";
            TMV.UpdateVKPOS(dwData, app.company, 20);
            dwData = TMV.VZB.TBMain.NewRow();
            dwData["VKZMANDANT"] = app.Mandant;
            dwData["VKZSA"] = "VK";
            dwData["VKZAUFKRS"] = dwMaster["VKPAUFKRS"];
            dwData["VKZAUFLFD"] = dwMaster["VKPAUFLFD"];
            dwData["VKZAUFPOS"] = " AND VKZAUFPOS='" + dwMaster["VKPAUFPOS"].ToString() + "'";
            TMV.VZB.UpdateVKZUAB(dwData, app.company, 20);// 无任何该动

            dwData = TMV.MUX.TBMain.NewRow();
            dwData["ABAMANDANT"] = app.Mandant;
            dwData["ABAVKAUFKRS"] = dwMaster["VKPAUFKRS"];
            dwData["ABAVKAUFLFD"] = dwMaster["VKPAUFLFD"];
            dwData["ABAVKAUFPOS"] = " AND ABAVKAUFPOS='" + dwMaster["VKPAUFPOS"].ToString() + "'";
            TMV.MUX.DeleteABAUFM(dwData, 20);

            dwData = TMV.VKD.TBMain.NewRow();
            dwData["VKAMANDANT"] = app.Mandant;
            dwData["VKAAUFKRS"] = dwMaster["VKPAUFKRS"];
            dwData["VKAAUFLFD"] = dwMaster["VKPAUFLFD"];
            dwData["VKAAUFPOS"] = " AND VKAAUFPOS='" + dwMaster["VKPAUFPOS"].ToString() + "'";

            dwData["VKASA"] = " ";
            TMV.VKD.DeleteVKADR(dwData, 20);

            dwData = TMV.VWD.TBMain.NewRow();
            dwData["WDMANDANT"] = app.Mandant;
            dwData["WDAUFKRS"] = dwMaster["VKPAUFKRS"];
            dwData["WDAUFLFD"] = dwMaster["VKPAUFLFD"];
            dwData["WDAUFPOS"] = " AND WDAUFPOS='" + dwMaster["VKPAUFPOS"].ToString() + "'";
            dwData["WDSA"] = "K";
            TMV.VWD.DeleteWDECK(dwData, 20);

            UpdateVK04(dwMaster["VKPAUFKRS"].ToString() + dwMaster["VKPAUFLFD"].ToString());

            base.InactiveCommand(sender, e);
        }

        public void NewVVTCommand(object sender, RoutedEventArgs e)
        {
            TMV.VVTNEW(dwMaster, dwVF, dwVKK);
            string key = AUF;
            AUF = "";
            AUF = key;
        }

        public void AddVVTCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            if (LIEFSCH.Length < 2)
            {
                return;
            }
            TMV.VVTADD(dwMaster, dwVF, LIEFSCH);
            string key = AUF;
            AUF = "";
            AUF = key;
        }

        public virtual void QTY_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {

            if (!IsEdit)
                return;

            if (e.Key != System.Windows.Input.Key.Enter)
                return;
            if (e.Key != System.Windows.Input.Key.Return)
                return;
            if (!Validate())
            {
                return;
            }

            dwMaster["VKPMEEH"] = MEEH;
            // dwMaster["VKPWUTERM"] = dwMaster["VKPLIEFTERM"];
            dwMaster["VKPFREITERM"] = dwMaster["VKPLIEFTERM"];
            dwMaster["VKPVERSTERM"] = dwMaster["VKPLIEFTERM"];
            dwMaster["VKPLIEFEING"] = dwMaster["VKPLIEFTERM"];

            UPDATEVKP(dwMaster);

            string _POS = dwVKP["VKPAUFPOS"].ToString();
            Copy();
        }
        public virtual void KD_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key != System.Windows.Input.Key.Enter)
                return;
            if (e.Key != System.Windows.Input.Key.Return)
                return;
            TextBox tb = sender as TextBox;
            this.Focus();
            string YD = TMV.VKPLIEFTERM.ToString();
            string HY = "";
            HY = VSDDAT.SD22.GETNEXT("0022", YD.Substring(2, 2), YD.Substring(4, 2), 1, 3);
            TMV.VKPKDKOMM = YD.Substring(2, 2) + "/" + YD.Substring(4, 2) + HY;
            tb.Focus();

        }

        private void UpdateVK04(string order)
        {
            dwData = VKK.TBMain.NewRow();
            dwData["VKKMANDANT"] = app.Mandant;
            dwData["VKKAUFKRS"] = order.Substring(0, 2);
            dwData["VKKAUFLFD"] = order.Substring(2, 6);
            VKK.UpdateVKKOPF(dwData, app.company, 5);
            WERT = "";
            WERT = "0";
        }

        public override void OnSave()
        {
            if (!IsSaved)
                return;
            if (dwMaster == null)
                return;
            UPDATEVKP(dwMaster);
            base.OnSave();

        }

        public override void SetUpUserRight()
        {
            base.SetUpUserRight();
            Type mom = this.GetType();
            if (mom == null)
                return;
            string filter = "USERID='" + app.User + "' AND PROG='" + mom.Name.PadRight(80) + "'";
            DataRow[] rows = TBUR.Select(filter);
            foreach (DataRow row in rows)
            {
                string contol = row["CONTROLS"].ToString();//属性 
                string PROCESS = row["PROCESS"].ToString();//控制值
                string txt = row["P0"].ToString();//文本值 
                bool blControl = true;
                if (PROCESS.Trim() == "N")
                {
                    blControl = false; ;
                }
                if (PROCESS.Trim() == "Y")
                {
                    blControl = true; ;
                }
                switch (contol.Trim())
                {
                    case "PAY":
                        //IsCanPay = blControl;
                        break;
                    case "CHGZA":
                        //IsChgZA = blControl;
                        break;
                }
            }
        }

        public virtual void OnKURSChg(string value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            if (value.Trim().Length == 0)
                return;
            foreach (DataRow _dwVKP in TBMain.Rows)
            {
                _dwVKP["VKPKURS"] = Helper.Right("0000000" + value, 7);
                UPDATEVKP(_dwVKP);
            }
        }

        public void VRPKOCommand(object sender, RoutedEventArgs e)
        {
            VKPKOAUF = "";
            if (TMV.VKPKOAUFPOS == "000")
                TMV.VKPKOAUFPOS = "001";
            VKPKOAUF = "K" + TMV.VKPKOAUFKRS + TMV.VKPKOAUFLFD + TMV.VKPKOAUFPOS;
        }

        public void VRManagement(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.VR02(RUNID, AUF);
        }
        public override void LOADBYAUF()
        {
            IsCanERL = false;
            if (!IsCanLoad)
                return;
            TBMain.Clear();
            if (ORDERNUM == "")
                return;
            KRS = ORDERNUM.Substring(0, 2);
            LFD = ORDERNUM.Substring(2, 6);
            POS = ORDERNUM.Substring(8, 3);
            dwData = TBMain.NewRow();
            dwData["VKPMANDANT"] = app.Mandant;
            dwData["VKPAUFKRS"] = KRS;
            dwData["VKPAUFLFD"] = LFD;
            dwData["VKPAUFPOS"] = POS;
            SResult = TMV.QVKP4ERL(dwData);
            MergeData(SResult, true);
            if (TBMain.Rows.Count > 0)
            {
                IsCanERL = true;
            }

        }

        public void ErlCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            string info = "订单已经成功结束";
            PM["EVENTID"] = "MVKPEND";
            bool IsReject = false;
            if (double.Parse(dwMaster["DIFF"].ToString()) < -2)
            {
                PM["EVENTID"] = "MVKPENDRJT";
                info = Helpers.Helper.ConvertGB2312To8859P1("订单数量" + TMV.VKPMENGE1 * 0.01 + ",发货数量" + TMV.VKPVERS * 0.01 + ":超过了" + double.Parse(dwMaster["DIFF"].ToString()) + " %.");
                IsReject = true;
            }
            PM["CUSER"] = app.User;
            PM["dwInput"] = dwMaster;
            PM["KRS"] = dwMaster["VKPAUFKRS"];
            PM["LFD"] = dwMaster["VKPAUFLFD"];
            PM["POS"] = dwMaster["VKPAUFPOS"];
            PM["MSG"] = new MessageInfo();
            PM["INFO"] = info;
            WFNEW = null;
            WFNEW = PM;
            IsNewWF = true;
            IsNewWF = false;
            if (IsReject)
                return;
            dwMaster["VKPERL"] ="J"; 
            dwMaster["VKPERLDAT"] = TMV.DBDATE;
            dwMaster["VKPEZEIT"] = TMV.DBTIME.PadRight(4).Substring(0,4);
            dwMaster["VKPERLBEN"] = app.User;
            TMV.UENDVKP(dwMaster);

        }

        public void OnERLAuditChg(bool _IsERLAudit)
        {
            if (!_IsERLAudit)
                return;
            if (dwMaster == null)
                return;
            string info = "订单已经成功结束";
            PM["EVENTID"] = "MVKPEND";
            PM["CUSER"] = app.User;
            PM["dwInput"] = dwMaster;
            PM["KRS"] = dwMaster["VKPAUFKRS"];
            PM["LFD"] = dwMaster["VKPAUFLFD"];
            PM["POS"] = dwMaster["VKPAUFPOS"];
            PM["MSG"] = new MessageInfo();
            PM["INFO"] = info;
            WFNEW = null;
            WFNEW = PM;
            IsNewWF = true;
            IsNewWF = false;
            dwMaster["VKPERL"] = "J"; 
            dwMaster["VKPERLDAT"] =TMV.DBDATE;
            dwMaster["VKPEZEIT"] = TMV.DBTIME.PadRight(4).Substring(0, 4);
            dwMaster["VKPERLBEN"] = app.User;
            TMV.UENDVKP(dwMaster);
        }
    }
    public partial class UIVKPOS
    {
        #region ==IsMTR===========
        public static readonly DependencyProperty IsMTRProperty = DependencyProperty.Register("IsMTR",
            typeof(bool), typeof(UIVKPOS),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsMTRChanged));
        public bool IsMTR
        {
            get
            {
                return (bool)GetValue(IsMTRProperty);
            }
            set
            {
                SetValue(IsMTRProperty, value);
            }
        }
        private static void OnIsMTRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsMTR = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsKG===========
        public static readonly DependencyProperty IsKGProperty = DependencyProperty.Register("IsKG",
            typeof(bool), typeof(UIVKPOS),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsKGChanged));
        public bool IsKG
        {
            get
            {
                return (bool)GetValue(IsKGProperty);
            }
            set
            {
                SetValue(IsKGProperty, value);
            }
        }
        private static void OnIsKGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsKG = (bool)e.NewValue;
            }
        }
        #endregion
        VVKKOPF _VKK;
        VVKKOPF VKK
        {
            get
            {
                if (_VKK == null) _VKK = new VVKKOPF();
                return _VKK;
            }
        }
        public VVKPOS TMV
        {
            get
            {
                return (VVKPOS)MV;
            }
        }

        #region ==CART===========
        public static readonly DependencyProperty CARTProperty = DependencyProperty.Register("CART",
            typeof(string), typeof(UIVKPOS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCARTChanged));
        public string CART
        {
            get
            {
                return (string)GetValue(CARTProperty);
            }
            set
            {
                SetValue(CARTProperty, value);
                OnCARTChg(value);
            }
        }
        private static void OnCARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.CART = (string)e.NewValue;
            }
        }
        public virtual void OnCARTChg(string value)
        { }
        #endregion
        #region ==IsCanERL===========
        public static readonly DependencyProperty IsCanERLProperty = DependencyProperty.Register("IsCanERL",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanERLChanged));
        public bool IsCanERL
        {
            get
            {
                return (bool)GetValue(IsCanERLProperty);
            }
            set
            {
                SetValue(IsCanERLProperty, value); 
            }
        }
        private static void OnIsCanERLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsCanERL = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==IsERLAudit===========
        public static readonly DependencyProperty IsERLAuditProperty = DependencyProperty.Register("IsERLAudit",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsERLAuditChanged));
        public bool IsERLAudit
        {
            get
            {
                return (bool)GetValue(IsERLAuditProperty);
            }
            set
            {
                SetValue(IsERLAuditProperty, value);
            }
        }
        private static void OnIsERLAuditChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsERLAudit = (bool)e.NewValue;
                src.OnERLAuditChg((bool)e.NewValue);
            }
        }
        #endregion
        
        #region ==IsShowSY===========
        public static readonly DependencyProperty IsShowSYProperty = DependencyProperty.Register("IsShowSY",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowSYChanged));
        public bool IsShowSY
        {
            get
            {
                return (bool)GetValue(IsShowSYProperty);
            }
            set
            {
                SetValue(IsShowSYProperty, value);
                IsShowMaster = !value;
            }
        }
        private static void OnIsShowSYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsShowSY = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowVK===========
        public static readonly DependencyProperty IsShowVKProperty = DependencyProperty.Register("IsShowVK",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowVKChanged));
        public bool IsShowVK
        {
            get
            {
                return (bool)GetValue(IsShowVKProperty);
            }
            set
            {
                SetValue(IsShowVKProperty, value);
                IsShowMaster = !value;
            }
        }
        private static void OnIsShowVKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsShowVK = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowCP===========
        public static readonly DependencyProperty IsShowCPProperty = DependencyProperty.Register("IsShowCP",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowCPChanged));
        public bool IsShowCP
        {
            get
            {
                return (bool)GetValue(IsShowCPProperty);
            }
            set
            {
                SetValue(IsShowCPProperty, value);
                IsShowMaster = !value;
            }
        }
        private static void OnIsShowCPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsShowCP = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowTG===========
        public static readonly DependencyProperty IsShowTGProperty = DependencyProperty.Register("IsShowTG",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowTGChanged));
        public bool IsShowTG
        {
            get
            {
                return (bool)GetValue(IsShowTGProperty);
            }
            set
            {
                SetValue(IsShowTGProperty, value);
                IsShowMaster = !value;
            }
        }
        private static void OnIsShowTGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsShowTG = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowVV===========
        public static readonly DependencyProperty IsShowVVProperty = DependencyProperty.Register("IsShowVV",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowVVChanged));
        public bool IsShowVV
        {
            get
            {
                return (bool)GetValue(IsShowVVProperty);
            }
            set
            {
                SetValue(IsShowVVProperty, value);
                IsShowMaster = !value;
            }
        }
        private static void OnIsShowVVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsShowVV = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowAB===========
        public static readonly DependencyProperty IsShowABProperty = DependencyProperty.Register("IsShowAB",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowABChanged));
        public bool IsShowAB
        {
            get
            {
                return (bool)GetValue(IsShowABProperty);
            }
            set
            {
                SetValue(IsShowABProperty, value);
                IsShowMaster = !value;
            }
        }
        private static void OnIsShowABChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsShowAB = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowMaster===========
        public static readonly DependencyProperty IsShowMasterProperty = DependencyProperty.Register("IsShowMaster",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowMasterChanged));
        public bool IsShowMaster
        {
            get
            {
                return (bool)GetValue(IsShowMasterProperty);
            }
            set
            {
                SetValue(IsShowMasterProperty, value);
            }
        }
        private static void OnIsShowMasterChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsShowMaster = (bool)e.NewValue;
            }
        }
        #endregion


        #region ==KURS===========
        public static readonly DependencyProperty KURSProperty = DependencyProperty.Register("KURS",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKURSChanged));
        public string KURS
        {
            get
            {
                return (string)GetValue(KURSProperty);
            }
            set
            {
                SetValue(KURSProperty, value);
                OnKURSChg(value);
            }
        }
        private static void OnKURSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.KURS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==LIEFTERM===========
        public static readonly DependencyProperty LIEFTERMProperty = DependencyProperty.Register("LIEFTERM",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("20160621", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLIEFTERMChanged));
        public string LIEFTERM
        {
            get
            {
                return (string)GetValue(LIEFTERMProperty);
            }
            set
            {
                SetValue(LIEFTERMProperty, value);
            }
        }
        private static void OnLIEFTERMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.LIEFTERM = (string)e.NewValue;
                src.OnLIEFTERMChg((string)e.NewValue);
            }
        }
        #endregion

        #region ==WAEHRSL===========
        public static readonly DependencyProperty WAEHRSLProperty = DependencyProperty.Register("WAEHRSL",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAEHRSLChanged));
        public string WAEHRSL
        {
            get
            {
                return (string)GetValue(WAEHRSLProperty);
            }
            set
            {
                SetValue(WAEHRSLProperty, value);
                OnWAEHRSLChg(value);
            }
        }
        private static void OnWAEHRSLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.WAEHRSL = (string)e.NewValue;
            }
        }
        public virtual void OnWAEHRSLChg(string value)
        { }
        #endregion

        #region ==NEUDATS===========
        public static readonly DependencyProperty NEUDATSProperty = DependencyProperty.Register("NEUDATS",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnNEUDATSChanged));
        public string NEUDATS
        {
            get
            {
                return (string)GetValue(NEUDATSProperty);
            }
            set
            {
                SetValue(NEUDATSProperty, value);
            }
        }
        private static void OnNEUDATSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.NEUDATS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==NEUDATE===========
        public static readonly DependencyProperty NEUDATEProperty = DependencyProperty.Register("NEUDATE",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnNEUDATEChanged));
        public string NEUDATE
        {
            get
            {
                return (string)GetValue(NEUDATEProperty);
            }
            set
            {
                SetValue(NEUDATEProperty, value);
            }
        }
        private static void OnNEUDATEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.NEUDATE = (string)e.NewValue;
            }
        }
        #endregion

        #region ==AUFART===========
        public static readonly DependencyProperty AUFARTProperty = DependencyProperty.Register("AUFART",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFARTChanged));
        public string AUFART
        {
            get
            {
                return (string)GetValue(AUFARTProperty);
            }
            set
            {
                SetValue(AUFARTProperty, value);

            }
        }
        private static void OnAUFARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.AUFART = (string)e.NewValue;
            }
        }
        #endregion
        #region ==VKKANSPRECH===========
        public static readonly DependencyProperty VKKANSPRECHProperty = DependencyProperty.Register("VKKANSPRECH",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKKANSPRECHChanged));
        public string VKKANSPRECH
        {
            get
            {
                return (string)GetValue(VKKANSPRECHProperty);
            }
            set
            {
                SetValue(VKKANSPRECHProperty, value);

            }
        }
        private static void OnVKKANSPRECHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VKKANSPRECH = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsAutoVRP===========
        public static readonly DependencyProperty IsAutoVRPProperty = DependencyProperty.Register("IsAutoVRP",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsAutoVRPChanged));
        public bool IsAutoVRP
        {
            get
            {
                return (bool)GetValue(IsAutoVRPProperty);
            }
            set
            {
                SetValue(IsAutoVRPProperty, value);
            }
        }
        private static void OnIsAutoVRPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsAutoVRP = (bool)e.NewValue;
            }
        }
        #endregion


        #region ==SACHBE===========
        public static readonly DependencyProperty SACHBEProperty = DependencyProperty.Register("SACHBE",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSACHBEChanged));
        public string SACHBE
        {
            get
            {
                return (string)GetValue(SACHBEProperty);
            }
            set
            {
                SetValue(SACHBEProperty, value);
            }
        }
        private static void OnSACHBEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.SACHBE = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KUNDNR===========
        public static readonly DependencyProperty KUNDNRProperty = DependencyProperty.Register("KUNDNR",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKUNDNRChanged));
        public string KUNDNR
        {
            get
            {
                return (string)GetValue(KUNDNRProperty);
            }
            set
            {
                SetValue(KUNDNRProperty, value);
            }
        }
        private static void OnKUNDNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.KUNDNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsShowWB===========
        public static readonly DependencyProperty IsShowWBProperty = DependencyProperty.Register("IsShowWB",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowWBChanged));
        public bool IsShowWB
        {
            get
            {
                return (bool)GetValue(IsShowWBProperty);
            }
            set
            {
                SetValue(IsShowWBProperty, value);
            }
        }
        private static void OnIsShowWBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsShowWB = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==YNE===========
        public static readonly DependencyProperty YNEProperty = DependencyProperty.Register("YNE",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnYNEChanged));
        public string YNE
        {
            get
            {
                return (string)GetValue(YNEProperty);
            }
            set
            {
                SetValue(YNEProperty, value);
            }
        }
        private static void OnYNEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.YNE = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDKOMM===========
        public static readonly DependencyProperty KDKOMMProperty = DependencyProperty.Register("KDKOMM",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDKOMMChanged));
        public string KDKOMM
        {
            get
            {
                return (string)GetValue(KDKOMMProperty);
            }
            set
            {
                SetValue(KDKOMMProperty, value);
            }
        }
        private static void OnKDKOMMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.KDKOMM = (string)e.NewValue;
            }
        }
        #endregion
        #region ==VKPKDKOMM===========
        public static readonly DependencyProperty VKPKDKOMMProperty = DependencyProperty.Register("VKPKDKOMM",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPKDKOMMChanged));
        public string VKPKDKOMM
        {
            get
            {
                return (string)GetValue(VKPKDKOMMProperty);
            }
            set
            {
                SetValue(VKPKDKOMMProperty, value);
            }
        }
        private static void OnVKPKDKOMMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VKPKDKOMM = (string)e.NewValue;
            }
        }
        #endregion

        #region ==BESTNR===========
        public static readonly DependencyProperty BESTNRProperty = DependencyProperty.Register("BESTNR",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBESTNRChanged));
        public string BESTNR
        {
            get
            {
                return (string)GetValue(BESTNRProperty);
            }
            set
            {
                SetValue(BESTNRProperty, value);
            }
        }
        private static void OnBESTNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.BESTNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==YARNTYP===========
        public static readonly DependencyProperty YARNTYPProperty = DependencyProperty.Register("YARNTYP",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnYARNTYPChanged));
        public string YARNTYP
        {
            get
            {
                return (string)GetValue(YARNTYPProperty);
            }
            set
            {
                SetValue(YARNTYPProperty, value);
            }
        }
        private static void OnYARNTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.YARNTYP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==SPINLOT===========
        public static readonly DependencyProperty SPINLOTProperty = DependencyProperty.Register("SPINLOT",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSPINLOTChanged));

        public string SPINLOT
        {
            get
            {
                return (string)GetValue(SPINLOTProperty);
            }
            set
            {
                SetValue(SPINLOTProperty, value);
                OnSpinLotChg();
            }

        }
        private static void OnSPINLOTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.SPINLOT = (string)e.NewValue;
            }
        }
        public virtual void OnSpinLotChg()
        {
            if (TMV != null)
                TMV.SPINLOT = SPINLOT;
        }
        #endregion

        #region ==VVT===========
        public static readonly DependencyProperty VVTProperty = DependencyProperty.Register("VVT",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVVTChanged));
        public string VVT
        {
            get
            {
                return (string)GetValue(VVTProperty);
            }
            set
            {
                SetValue(VVTProperty, value);
            }
        }
        private static void OnVVTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VVT = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsNOTFull===========
        public static readonly DependencyProperty IsNOTFullProperty = DependencyProperty.Register("IsNOTFull",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsNOTFullChanged));
        public bool IsNOTFull
        {
            get
            {
                return (bool)GetValue(IsNOTFullProperty);
            }
            set
            {
                SetValue(IsNOTFullProperty, value);
                if (MV == null)
                    return;
                TMV.IsNOTFull = value;
            }
        }
        private static void OnIsNOTFullChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsNOTFull = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==dwMEEH===========
        public static readonly DependencyProperty dwMEEHProperty = DependencyProperty.Register("dwMEEH",
        typeof(DataRow), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwMEEHChanged));
        public DataRow dwMEEH
        {
            get
            {
                return (DataRow)GetValue(dwMEEHProperty);
            }
            set
            {
                SetValue(dwMEEHProperty, value);
                if (dwMEEH == null)
                    return;
                if (IsEdit && dwMaster != null)
                {
                    dwMaster["VKPMEEH"] = dwMEEH["KEY"];
                    dwMaster["VKPMEEHGRP"] = dwMEEH["SDDATEN"].ToString().Substring(38, 1);
                    dwMaster["VKPMEEHFKT"] = dwMEEH["SDDATEN"].ToString().Substring(39, 12);
                    dwMaster["VKPPREHGRP"] = dwMaster["VKPMEEHGRP"];
                    dwMaster["VKPPREHFKT"] = dwMaster["VKPMEEHFKT"];
                    /*AEKG kg4000001100000EKG 00000000  KAREN 20011220 000000000000*
                    AGramm 4000000001000Gramm 00000000  INTEXV 20130111 000000000000*
                    * */
                }
            }
        }
        private static void OndwMEEHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            DataRow row = (DataRow)e.NewValue;
            if (src != null)
            {
                src.dwMEEH = row;
            }
        }
        #endregion

        #region ==MEEH===========
        public static readonly DependencyProperty MEEHProperty = DependencyProperty.Register("MEEH",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMEEHChanged));
        public string MEEH
        {
            get
            {
                return (string)GetValue(MEEHProperty);
            }
            set
            {
                SetValue(MEEHProperty, value);
                OnMEEHChg();

            }
        }
        private static void OnMEEHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.MEEH = (string)e.NewValue;
            }
        }
        public virtual void OnMEEHChg()
        {
            if (IsEdit && dwMaster != null)
            {
                dwMaster["VKPMEEH"] = MEEH.PadRight(3);
            }
        }
        #endregion
        #region ==UMLMS===========
        public static readonly DependencyProperty UMLMSProperty = DependencyProperty.Register("UMLMS",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnUMLMSChanged));
        public string UMLMS
        {
            get
            {
                return (string)GetValue(UMLMSProperty);
            }
            set
            {
                SetValue(UMLMSProperty, value);
                OnUMLMSChg();

            }
        }
        private static void OnUMLMSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.UMLMS = (string)e.NewValue;
            }
        }
        public virtual void OnUMLMSChg()
        {
        }

        #endregion

        #region ==BPRICE===========
        public static readonly DependencyProperty BPRICEProperty = DependencyProperty.Register("BPRICE",
        typeof(double), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBPRICEChanged));
        public double BPRICE
        {
            get
            {
                return (double)GetValue(BPRICEProperty);
            }
            set
            {
                SetValue(BPRICEProperty, value);


            }
        }
        private static void OnBPRICEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.BPRICE = (double)e.NewValue;
                src.OnBPRICEChg((double)e.NewValue);
            }
        }
        public virtual void OnBPRICEChg(double bprice)
        {
            
        }

        #endregion
        #region ==MYCOM===========
        public static readonly DependencyProperty MYCOMProperty = DependencyProperty.Register("MYCOM",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMYCOMChanged));
        public string MYCOM
        {
            get
            {
                return (string)GetValue(MYCOMProperty);
            }
            set
            {
                SetValue(MYCOMProperty, value);
            }
        }
        private static void OnMYCOMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.MYCOM = (string)e.NewValue;
            }
        }
        #endregion 
        #region ==MYBON===========
        public static readonly DependencyProperty MYBONProperty = DependencyProperty.Register("MYBON",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMYBONChanged));
        public string MYBON
        {
            get
            {
                return (string)GetValue(MYBONProperty);
            }
            set
            {
                SetValue(MYBONProperty, value);
            }
        }
        private static void OnMYBONChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.MYBON = (string)e.NewValue;
            }
        }
        #endregion

        #region ==RAWPRICE===========
        public static readonly DependencyProperty RAWPRICEProperty = DependencyProperty.Register("RAWPRICE",
        typeof(double), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRAWPRICEChanged));
        public double RAWPRICE
        {
            get
            {
                return (double)GetValue(RAWPRICEProperty);
            }
            set
            {
                SetValue(RAWPRICEProperty, value);
                OnRAWPRICEChg();

            }
        }
        private static void OnRAWPRICEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.RAWPRICE = (double)e.NewValue;
            }
        }
        public virtual void OnRAWPRICEChg()
        {
        }

        #endregion

        #region ==RATEOST===========
        public static readonly DependencyProperty RATEOSTProperty = DependencyProperty.Register("RATEOST",
        typeof(double), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRATEOSTChanged));
        public double RATEOST
        {
            get
            {
                return (double)GetValue(RATEOSTProperty);
            }
            set
            {
                SetValue(RATEOSTProperty, value);
            }
        }
        private static void OnRATEOSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.RATEOST = (double)e.NewValue;
                src.OnBPRICEChg((double)e.NewValue);
            }
        }
        #endregion

        #region ==MCOST===========
        public static readonly DependencyProperty MCOSTProperty = DependencyProperty.Register("MCOST",
        typeof(double), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMCOSTChanged));
        public double MCOST
        {
            get
            {
                return (double)GetValue(MCOSTProperty);
            }
            set
            {
                SetValue(MCOSTProperty, value);

            }
        }
        private static void OnMCOSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.MCOST = (double)e.NewValue;
                src.OnMCOSTChg((double)e.NewValue);
            }
        }
        public virtual void OnMCOSTChg(double value)
        {

        }
        #endregion
        #region ==GRPROFIT===========
        public static readonly DependencyProperty GRPROFITProperty = DependencyProperty.Register("GRPROFIT",
        typeof(double), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnGRPROFITChanged));
        public double GRPROFIT
        {
            get
            {
                return (double)GetValue(GRPROFITProperty);
            }
            set
            {
                SetValue(GRPROFITProperty, value);

            }
        }
        private static void OnGRPROFITChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.GRPROFIT = (double)e.NewValue;
                src.OnGRPROFITChg((double)e.NewValue);
            }
        }
        public virtual void OnGRPROFITChg(double value)
        {
            OnDPRODChg(value);
        }
        #endregion
        #region ==LOOMPROFIT===========
        public static readonly DependencyProperty LOOMPROFITProperty = DependencyProperty.Register("LOOMPROFIT",
        typeof(double), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLOOMPROFITChanged));
        public double LOOMPROFIT
        {
            get
            {
                return (double)GetValue(LOOMPROFITProperty);
            }
            set
            {
                SetValue(LOOMPROFITProperty, value);

            }
        }
        private static void OnLOOMPROFITChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.LOOMPROFIT = (double)e.NewValue;
                src.OnLOOMPROFITChg((double)e.NewValue);
            }
        }
        public virtual void OnLOOMPROFITChg(double value)
        {

        }
        #endregion
        #region ==VB===========
        public static readonly DependencyProperty VBProperty = DependencyProperty.Register("VB",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVBChanged));
        public string VB
        {
            get
            {
                return (string)GetValue(VBProperty);
            }
            set
            {
                SetValue(VBProperty, value);
            }
        }
        private static void OnVBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VB = (string)e.NewValue;
                src.OnVBChg((string)e.NewValue);
            }
        }
        public virtual void OnVBChg(string value)
        {
            
        }
        #endregion
        #region ==DPROD===========
        public static readonly DependencyProperty DPRODProperty = DependencyProperty.Register("DPROD",
        typeof(double), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDPRODChanged));
        public double DPROD
        {
            get
            {
                return (double)GetValue(DPRODProperty);
            }
            set
            {
                SetValue(DPRODProperty, value);

            }
        }
        private static void OnDPRODChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.DPROD = (double)e.NewValue;
            }
        }
        public virtual void OnDPRODChg(double value)
        {

        }
        #endregion


        #region ==IsPrice===========
        public static readonly DependencyProperty IsPriceProperty = DependencyProperty.Register("IsPrice",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsPriceChanged));
        public bool IsPrice
        {
            get
            {
                return (bool)GetValue(IsPriceProperty);
            }
            set
            {
                SetValue(IsPriceProperty, value);
                if (MV == null)
                    return;
                TMV.IsPrice = value;
            }
        }
        private static void OnIsPriceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsPrice = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsStagePrice===========
        public static readonly DependencyProperty IsStagePriceProperty = DependencyProperty.Register("IsStagePrice",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsStagePriceChanged));
        public bool IsStagePrice
        {
            get
            {
                return (bool)GetValue(IsStagePriceProperty);
            }
            set
            {
                SetValue(IsStagePriceProperty, value);
                if (MV == null)
                    return;
            }
        }
        private static void OnIsStagePriceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsStagePrice = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsVV===========
        public static readonly DependencyProperty IsVVProperty = DependencyProperty.Register("IsVV",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsVVChanged));
        public bool IsVV
        {
            get
            {
                return (bool)GetValue(IsVVProperty);
            }
            set
            {
                SetValue(IsVVProperty, value);
                if (MV == null) return;
                TMV.IsVV = value;
            }
        }
        private static void OnIsVVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsVV = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsNVV===========
        public static readonly DependencyProperty IsNVVProperty = DependencyProperty.Register("IsNVV",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsNVVChanged));
        public bool IsNVV
        {
            get
            {
                return (bool)GetValue(IsNVVProperty);
            }
            set
            {
                SetValue(IsNVVProperty, value);
            }
        }
        private static void OnIsNVVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsNVV = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCheckVA===========
        public static readonly DependencyProperty IsCheckVAProperty = DependencyProperty.Register("IsCheckVA",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCheckVAChanged));
        public bool IsCheckVA
        {
            get
            {
                return (bool)GetValue(IsCheckVAProperty);
            }
            set
            {
                SetValue(IsCheckVAProperty, value);
            }
        }
        private static void OnIsCheckVAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsCheckVA = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==dwVKK===========
        public static readonly DependencyProperty dwVKKProperty = DependencyProperty.Register("dwVKK",
        typeof(DataRow), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVKKChanged));
        public DataRow dwVKK
        {
            get
            {
                return (DataRow)GetValue(dwVKKProperty);
            }
            set
            {
                SetValue(dwVKKProperty, value);
                OnVKKChg(value);

            }
        }
        private static void OndwVKKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            DataRow row = (DataRow)e.NewValue;
            if (src != null)
            {
                src.dwVKK = row;
            }
        }
        #endregion

        #region ==VKP===========
        public static readonly DependencyProperty VKPProperty = DependencyProperty.Register("VKP",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPChanged));
        public string VKP
        {
            get
            {
                return (string)GetValue(VKPProperty);
            }
            set
            {
                SetValue(VKPProperty, value);
            }
        }
        private static void OnVKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VKP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==OVERSHORT===========
        public static readonly DependencyProperty OVERSHORTProperty = DependencyProperty.Register("OVERSHORT",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnOVERSHORTChanged));
        public string OVERSHORT
        {
            get
            {
                return (string)GetValue(OVERSHORTProperty);
            }
            set
            {
                SetValue(OVERSHORTProperty, value);
                OnOVERSHORTChg();
            }
        }
        private static void OnOVERSHORTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.OVERSHORT = (string)e.NewValue;
            }
        }
        public virtual void OnOVERSHORTChg()
        { }
        #endregion

        #region ==PCS===========
        public static readonly DependencyProperty PCSProperty = DependencyProperty.Register("PCS",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPCSChanged));
        public string PCS
        {
            get
            {
                return (string)GetValue(PCSProperty);
            }
            set
            {
                SetValue(PCSProperty, value);
                OnPCSChg();
            }
        }
        private static void OnPCSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.PCS = (string)e.NewValue;
            }
        }
        public virtual void OnPCSChg()
        { }
        #endregion

        #region ==AUF===========
        public static readonly DependencyProperty AUFProperty = DependencyProperty.Register("AUF",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFChanged));
        public string AUF
        {
            get
            {
                return (string)GetValue(AUFProperty);
            }
            set
            {
                SetValue(AUFProperty, value);
                OnAUFChg(value);
            }
        }
        private static void OnAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.AUF = (string)e.NewValue;
            }
        }
        public virtual void OnAUFChg(string auf)
        {
        }
        #endregion

        #region ==VKPKOAUF===========
        public static readonly DependencyProperty VKPKOAUFProperty = DependencyProperty.Register("VKPKOAUF",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPKOAUFChanged));
        public string VKPKOAUF
        {
            get
            {
                return (string)GetValue(VKPKOAUFProperty);
            }
            set
            {
                SetValue(VKPKOAUFProperty, value);
            }
        }
        private static void OnVKPKOAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VKPKOAUF = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsCanAdd===========
        public static readonly DependencyProperty IsCanAddProperty = DependencyProperty.Register("IsCanAdd",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCanAddChanged));
        public bool IsCanAdd
        {
            get
            {
                return (bool)GetValue(IsCanAddProperty);
            }
            set
            {
                SetValue(IsCanAddProperty, value);
            }
        }
        private static void OnIsCanAddChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsCanAdd = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==dwVKP===========
        public static readonly DependencyProperty dwVKPProperty = DependencyProperty.Register("dwVKP",
        typeof(DataRow), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVKPChanged));
        public DataRow dwVKP
        {
            get
            {
                return (DataRow)GetValue(dwVKPProperty);
            }
            set
            {
                SetValue(dwVKPProperty, value);
                if (MV == null) return;
                TMV.dwVKP = value;
            }
        }
        private static void OndwVKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            DataRow row = (DataRow)e.NewValue;
            if (src != null)
            {
                src.dwVKP = row;
            }
        }
        #endregion

        #region ==dwVF===========
        public static readonly DependencyProperty dwVFProperty = DependencyProperty.Register("dwVF",
        typeof(DataRow), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVFChanged));
        public DataRow dwVF
        {
            get
            {
                return (DataRow)GetValue(dwVFProperty);
            }
            set
            {
                SetValue(dwVFProperty, value);
                OnVAFChg(value);


            }
        }
        public virtual void OnVAFChg(DataRow _dwVF)
        {
            if (_dwVF == null)
            {
                return;
            }
            if (dwMain == null)
                return;
            if (!IsEdit)
                return;
            try
            {
                dwMaster["VKPKOLL"] = _dwVF["VAFKOLL"];
                dwMaster["VKPART"] = _dwVF["VAFART"];
                dwMaster["VKPFARBE"] = _dwVF["VAFFARBE"];
                dwMaster["VKPPRGR"] = _dwVF["VAAPRGR"];
                dwMaster["VKPARTGRP"] = _dwVF["VAAARTGRP"];
                dwMaster["VAFBEZ"] = _dwVF["VAFBEZ"];
                dwMaster["VAABEZ"] = _dwVF["VAABEZ"];

                CheckPrice(dwMaster);
                CheckDelDate(dwMaster);
                if (dwMain == null)
                { }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private static void OndwVFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.dwVF = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==VKPAUFMART===========
        public static readonly DependencyProperty VKPAUFMARTProperty = DependencyProperty.Register("VKPAUFMART",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPAUFMARTChanged));
        public string VKPAUFMART
        {
            get
            {
                return (string)GetValue(VKPAUFMARTProperty);
            }
            set
            {
                SetValue(VKPAUFMARTProperty, value);
            }
        }
        private static void OnVKPAUFMARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VKPAUFMART = (string)e.NewValue;
                if (src.TMV == null)
                    return;
                src.TMV.VKPAUFMART = ((string)e.NewValue).PadRight(2);
            }
        }
        #endregion

        #region ==VKPVERPART===========
        public static readonly DependencyProperty VKPVERPARTProperty = DependencyProperty.Register("VKPVERPART",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPVERPARTChanged));
        public string VKPVERPART
        {
            get
            {
                return (string)GetValue(VKPVERPARTProperty);
            }
            set
            {
                SetValue(VKPVERPARTProperty, value);
            }
        }
        private static void OnVKPVERPARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VKPVERPART = (string)e.NewValue;
                if (src.TMV == null)
                    return;
                src.TMV.VKPVERPART = ((string)e.NewValue).PadRight(3);
            }
        }
        #endregion

        #region ==IsPringPR===========
        public static readonly DependencyProperty IsPringPRProperty = DependencyProperty.Register("IsPringPR",
            typeof(bool), typeof(UIVKPOS),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsPringPRChanged));
        public bool IsPringPR
        {
            get
            {
                return (bool)GetValue(IsPringPRProperty);
            }
            set
            {
                SetValue(IsPringPRProperty, value);
            }
        }
        private static void OnIsPringPRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsPringPR = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==IsPringPREN===========
        public static readonly DependencyProperty IsPringPRENProperty = DependencyProperty.Register("IsPringPREN",
            typeof(bool), typeof(UIVKPOS),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsPringPRENChanged));
        public bool IsPringPREN
        {
            get
            {
                return (bool)GetValue(IsPringPRENProperty);
            }
            set
            {
                SetValue(IsPringPRENProperty, value);
            }
        }
        private static void OnIsPringPRENChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsPringPREN = (bool)e.NewValue;
            }
        }
        #endregion
        #region ==IsPringPRCN===========
        public static readonly DependencyProperty IsPringPRCNProperty = DependencyProperty.Register("IsPringPRCN",
            typeof(bool), typeof(UIVKPOS),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsPringPRCNChanged));
        public bool IsPringPRCN
        {
            get
            {
                return (bool)GetValue(IsPringPRCNProperty);
            }
            set
            {
                SetValue(IsPringPRCNProperty, value);
            }
        }
        private static void OnIsPringPRCNChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsPringPRCN = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==PIND===========
        public static readonly DependencyProperty PINDProperty = DependencyProperty.Register("PIND",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPINDChanged));
        public string PIND
        {
            get
            {
                return (string)GetValue(PINDProperty);
            }
            set
            {
                SetValue(PINDProperty, value);
            }
        }
        private static void OnPINDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.PIND = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VKPPIND===========
        public static readonly DependencyProperty VKPPINDProperty = DependencyProperty.Register("VKPPIND",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPPINDChanged));
        public string VKPPIND
        {
            get
            {
                return (string)GetValue(VKPPINDProperty);
            }
            set
            {
                SetValue(VKPPINDProperty, value);
            }
        }
        private static void OnVKPPINDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VKPPIND = (string)e.NewValue;
            }
        }
        #endregion

        #region ==TXTVKPSIND===========
        public static readonly DependencyProperty TXTVKPSINDProperty = DependencyProperty.Register("TXTVKPSIND",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTXTVKPSINDChanged));
        public string TXTVKPSIND
        {
            get
            {
                return (string)GetValue(TXTVKPSINDProperty);
            }
            set
            {
                SetValue(TXTVKPSINDProperty, value);
            }
        }
        private static void OnTXTVKPSINDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.TXTVKPSIND = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VART===========
        public static readonly DependencyProperty VARTProperty = DependencyProperty.Register("VART",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVARTChanged));
        public string VART
        {
            get
            {
                return (string)GetValue(VARTProperty);
            }
            set
            {
                SetValue(VARTProperty, value);
                if (MV == null) return;
                TMV.VART = value;
            }
        }
        private static void OnVARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==QCOND===========
        public static readonly DependencyProperty QCONDProperty = DependencyProperty.Register("QCOND",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnQCONDChanged));
        public string QCOND
        {
            get
            {
                return (string)GetValue(QCONDProperty);
            }
            set
            {
                SetValue(QCONDProperty, value);
                OnQCONDChg();
            }
        }
        private static void OnQCONDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.QCOND = (string)e.NewValue;
            }
        }
        public virtual void OnQCONDChg()
        {

        }
        #endregion

        #region ==PRART===========
        public static readonly DependencyProperty PRARTProperty = DependencyProperty.Register("PRART",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRARTChanged));
        public string PRART
        {
            get
            {
                return (string)GetValue(PRARTProperty);
            }
            set
            {
                SetValue(PRARTProperty, value);
            }
        }
        private static void OnPRARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.PRART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==POSTYP===========
        public static readonly DependencyProperty POSTYPProperty = DependencyProperty.Register("POSTYP",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPOSTYPChanged));
        public string POSTYP
        {
            get
            {
                return (string)GetValue(POSTYPProperty);
            }
            set
            {
                SetValue(POSTYPProperty, value);
            }
        }
        private static void OnPOSTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.POSTYP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VKPSA===========
        public static readonly DependencyProperty VKPSAProperty = DependencyProperty.Register("VKPSA",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPSAChanged));
        public string VKPSA
        {
            get
            {
                return (string)GetValue(VKPSAProperty);
            }
            set
            {
                SetValue(VKPSAProperty, value);
            }
        }
        private static void OnVKPSAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.VKPSA = (string)e.NewValue;
            }
        }
        #endregion

        #region ==BSTSTA===========
        public static readonly DependencyProperty BSTSTAProperty = DependencyProperty.Register("BSTSTA",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBSTSTAChanged));
        public string BSTSTA
        {
            get
            {
                return (string)GetValue(BSTSTAProperty);
            }
            set
            {
                SetValue(BSTSTAProperty, value);
            }
        }
        private static void OnBSTSTAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.BSTSTA = (string)e.NewValue;
            }
        }
        #endregion

        #region ==LIEFSCH===========
        public static readonly DependencyProperty LIEFSCHProperty = DependencyProperty.Register("LIEFSCH",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLIEFSCHChanged));
        public string LIEFSCH
        {
            get
            {
                return (string)GetValue(LIEFSCHProperty);
            }
            set
            {
                SetValue(LIEFSCHProperty, value);
                if (MV == null) return;
                TMV.LIEFSCH = LIEFSCH;
                if (dwVKP == null)
                    return;
                VVT = dwVKP["VKPAUFKRS"].ToString() + dwVKP["VKPAUFLFD"].ToString() + dwVKP["VKPAUFPOS"].ToString() + LIEFSCH.PadRight(8) + "K";

            }
        }
        private static void OnLIEFSCHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.LIEFSCH = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsOrder===========
        public static readonly DependencyProperty IsOrderProperty = DependencyProperty.Register("IsOrder",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsOrderChanged));
        public bool IsOrder
        {
            get
            {
                return (bool)GetValue(IsOrderProperty);
            }
            set
            {
                SetValue(IsOrderProperty, value);
            }
        }
        private static void OnIsOrderChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsOrder = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsBasedOnOF===========
        public static readonly DependencyProperty IsBasedOnOFProperty = DependencyProperty.Register("IsBasedOnOF",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsBasedOnOFChanged));
        public bool IsBasedOnOF
        {
            get
            {
                return (bool)GetValue(IsBasedOnOFProperty);
            }
            set
            {
                SetValue(IsBasedOnOFProperty, value);
            }
        }
        private static void OnIsBasedOnOFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsBasedOnOF = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCopyTxtMode===========
        public static readonly DependencyProperty IsCopyTxtModeProperty = DependencyProperty.Register("IsCopyTxtMode",
        typeof(bool), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCopyTxtModeChanged));
        public bool IsCopyTxtMode
        {
            get
            {
                return (bool)GetValue(IsCopyTxtModeProperty);
            }
            set
            {
                SetValue(IsCopyTxtModeProperty, value);
            }
        }
        private static void OnIsCopyTxtModeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.IsCopyTxtMode = (bool)e.NewValue;
                src.OnCopyTxtModeChg((bool)e.NewValue);
            }
        }
        public virtual void OnCopyTxtModeChg(bool copymode)
        {

        }
        #endregion

        

        #region ==WERT===========
        public static readonly DependencyProperty WERTProperty = DependencyProperty.Register("WERT",
        typeof(string), typeof(UIVKPOS),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWERTChanged));
        public string WERT
        {
            get
            {
                return (string)GetValue(WERTProperty);
            }
            set
            {
                SetValue(WERTProperty, value);
            }
        }
        private static void OnWERTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.WERT = (string)e.NewValue;
            }
        }
        #endregion

        #region ==BUVALUE===========
        public static readonly DependencyProperty BUVALUEProperty = DependencyProperty.Register("BUVALUE",
        typeof(double), typeof(UIVKPOS),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBUVALUEChanged));
        public double BUVALUE
        {
            get
            {
                return (double)GetValue(BUVALUEProperty);
            }
            set
            {
                SetValue(BUVALUEProperty, value);
            }
        }
        private static void OnBUVALUEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKPOS;
            if (src != null)
            {
                src.BUVALUE = (double)e.NewValue;
            }
        }
        #endregion
        public TextBox TxtQty { get { return (TextBox)this.FindName("txtQty"); } }
        public TextBox TxtPrice { get { return (TextBox)this.FindName("txtPrice"); } }
        public TNOVA10 cNOVA { get { return (TNOVA10)this.FindName("cNOVA"); } }

    }
}
